package com.PengGoBook.main.utils;

import android.content.Context;
import android.util.Log;
import org.apache.http.NameValuePair;

/**
 * Created with IntelliJ IDEA.
 * User: S7
 * Date: 13-5-28
 * Time: 上午1:45
 * To change this template use File | Settings | File Templates.
 */
public class HttpUtils {
    // 网络连接部分
    public static String postByHttpURLConnection(String strUrl,
                                                 NameValuePair... nameValuePairs) {
        return CustomHttpURLConnection.PostFromWebByHttpURLConnection(strUrl,
                nameValuePairs);
    }

    public static String getByHttpURLConnection(String strUrl,
                                                NameValuePair... nameValuePairs) {
        return CustomHttpURLConnection.GetFromWebByHttpUrlConnection(strUrl,
                nameValuePairs);
    }

    public static String postByHttpClient(Context context,String strUrl,
                                          NameValuePair... nameValuePairs) {
        return CustomHttpClient.PostFromWebByHttpClient(context,strUrl, nameValuePairs);
    }

    public static String getByHttpClient(Context context,String strUrl,
                                         NameValuePair... nameValuePairs) throws Exception {
        return CustomHttpClient.getFromWebByHttpClient(context,strUrl, nameValuePairs);
    }

    // ------------------------------------------------------------------------------------------
    // 网络连接判断
    // 判断是否有网络
//	public static boolean isNetworkAvailable(Context context) {
//		return NetWorkHelper.isNetworkAvailable(context);
//	}

    // 判断mobile网络是否可用
    public static boolean isMobileDataEnable(Context context) {
        String TAG = "httpUtils.isMobileDataEnable()";
        try {
            return NetWorkHelper.isMobileDataEnable(context);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            Log.e(TAG, e.getMessage());
            e.printStackTrace();
            return false;
        }
    }

    // 判断wifi网络是否可用
    public static boolean isWifiDataEnable(Context context) {
        String TAG = "httpUtils.isWifiDataEnable()";
        try {
            return NetWorkHelper.isWifiDataEnable(context);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            Log.e(TAG, e.getMessage());
            e.printStackTrace();
            return false;
        }
    }

    // 设置Mobile网络开关
    public static void setMobileDataEnabled(Context context, boolean enabled) {
        String TAG = "httpUtils.setMobileDataEnabled";
        try {
            NetWorkHelper.setMobileDataEnabled(context, enabled);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            Log.e(TAG, e.getMessage());
            e.printStackTrace();
        }
    }

    // 判断是否为漫游
    public static boolean isNetworkRoaming(Context context) {
        return NetWorkHelper.isNetworkRoaming(context);
    }
}